<template>
  <div class="main-content noBorder">

    <el-tabs type="border-card">

      <!--资源文件-->
      <el-tab-pane>
        <template #label>
          <el-icon>
            <Money/>
          </el-icon>
          <span style="margin-left: 2px">资源文件</span>
        </template>
        <SysStaticRes></SysStaticRes>
      </el-tab-pane>

      <!--  参数配置-->
      <el-tab-pane>
        <template #label>
          <el-icon>
            <el-icon>
              <ChromeFilled/>
            </el-icon>
          </el-icon>
          <span style="margin-left: 2px">参数配置</span>
        </template>
        <el-form ref="formDataRef" size="default" :model="formData" :rules="formRules">

          <el-input v-model="formData.sys_file_minio_url_prefix" style="width: 600px" placeholder="请输入" class="pd8">
            <template #prepend>
              <div class="fx_center_center" style="width:70px">访问地址</div>
            </template>
          </el-input>

          <br>
          <el-input v-model="formData.sys_file_minio_endpoint" style="width: 600px" placeholder="请输入" class="pd8">
            <template #prepend>
              <div class="fx_center_center" style="width:70px">endpoint</div>
            </template>
          </el-input>

          <br>
          <el-input v-model="formData.sys_file_minio_access_key" style="width: 600px" placeholder="请输入" class="pd8">
            <template #prepend>
              <div class="fx_center_center" style="width:70px">accessKey</div>
            </template>
          </el-input>

          <br>
          <el-input v-model="formData.sys_file_minio_secret_key" style="width: 600px" placeholder="请输入" class="pd8">
            <template #prepend>
              <div class="fx_center_center" style="width:70px">secretKey</div>
            </template>
          </el-input>

          <br>
          <el-input v-model="formData.sys_file_minio_bucket_name" style="width: 600px" placeholder="请输入" class="pd8">
            <template #prepend>
              <div class="fx_center_center" style="width:70px">bucketName</div>
            </template>
          </el-input>

        </el-form>


        <div class="fx_center_center pd16">
          <el-button type="primary" @click="submitEdit" style="width: 200px" size="large">保 存</el-button>
        </div>
      </el-tab-pane>

    </el-tabs>


  </div>

</template>

<script setup>
import {getCurrentInstance, onMounted, ref} from "vue";
import $modal from "@/common/utils/modal";
import {selectSetting, updateSetting} from "@/common/api/system";
import SysStaticRes from "@/module/common/sysStaticRes.vue";

const {proxy} = getCurrentInstance();

let optionKey = {
  loading: false,
}

let formKey = {
  sys_file_minio_url_prefix: "",
  sys_file_minio_access_key: "",
  sys_file_minio_secret_key: "",
  sys_file_minio_bucket_name: "",
  sys_file_minio_endpoint: "",
}

const formRules = ref({
  sys_file_minio_url_prefix: [{required: true, message: "不能为空", trigger: "blur"}],
  sys_file_minio_endpoint: [{required: true, message: "不能为空", trigger: "blur"}],
  sys_file_minio_access_key: [{required: true, message: "不能为空", trigger: "blur"}],
  sys_file_minio_secret_key: [{required: true, message: "不能为空", trigger: "blur"}],
  sys_file_minio_bucket_name: [{required: true, message: "不能为空", trigger: "blur"}],
});


const option = ref(optionKey);

const formData = ref(formKey);


//页面加载完成回调
onMounted(() => {
  searchData()
})

//搜索数据
function searchData() {
  let keys = Object.keys(formData.value).join(",")

  selectSetting({keys}).then(res => {
    if (res.success) {
      formData.value = res.data
    }
  })

}

function submitEdit() {
  //console.log("formData.value  ", formData.value)
  let content = `正在修改配置信息，请确认是否继续操作？ `
  $modal.confirmWarning(content).then(() => {
    proxy.$refs["formDataRef"].validate(valid => {
      if (valid) {
        updateSetting(formData.value).then(res => {
          if (res.success) {
            $modal.success();
          }
        })
      }
    });
  }).catch(() => $modal.cancel());
}
</script>

<style scoped lang="less">

</style>